<template>
  <div>
    <el-breadcrumb>
      <el-breadcrumb-item>事件查询</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 表单查询 -->
    <el-card>
      <el-table :data="userlist" stripe style="width: 100%">>
        <el-table-column prop="s_id" label="事件ID" width="400">
        </el-table-column>
        <el-table-column prop="s_pid" label="人员ID" width="400">
        </el-table-column>
        <el-table-column prop="s_name" label="姓名" width="400">
        </el-table-column>
        <el-table-column prop="s_time" label="发生日期">
        </el-table-column>
        <el-table-column prop="s_type" label="事件类型">
        </el-table-column>
        <el-table-column prop="s_about" label="事件描述">
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 修改对话框 -->
    <el-dialog :visible.sync="updataDialogVisible" width="30%">
      <el-form :model="formvalue" label-width="80px">
        <el-form-item label="事件ID">
          <el-input v-model="formvalue.s_id" :disabled="true"></el-input>
        </el-form-item>
           <el-form-item label="人员ID">
          <el-input v-model="formvalue.s_pid"></el-input>
        </el-form-item>
        <el-form-item label="姓名">
          <el-input v-model="formvalue.s_name"></el-input>
        </el-form-item>
        <el-form-item label="发生日期">
          <el-input v-model="formvalue.s_time"></el-input>
        </el-form-item>
        <el-form-item label="事件类型">
          <el-input v-model="formvalue.s_type"></el-input>
        </el-form-item>
        <el-form-item label="事件描述">
          <el-input v-model="formvalue.s_about"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="updataDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="updataUser">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 删除对话框 -->
    <el-dialog :visible.sync="deleteDialogVisible" width="30%">
      <el-form :model="formvalue" label-width="80px">
      </el-form>
      <el-dialog title="提示" :visible.sync="sucessVisible" width="30%">
        <span>确定录入？</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="sucessVisible = false">取 消</el-button>
          <el-button type="primary" @click="sucessVisible = false">确 定</el-button>
        </span>
      </el-dialog>
      <span slot="footer" class="dialog-footer">
        <el-button @click="deleteDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dleteUser">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userlist: [],
      updataDialogVisible: false,
      deleteDialogVisible: false,
      formvalue: {}
    }
  },
  created() {
    this.getUserlist()
  },
  methods: {
    // 获取用户的信息列表
    async getUserlist() {
      const { data: res } = await this.$http.get('story')
      this.userlist = res.data.value
    },
    // 展示用户的修改对话框
    showUpdataDialog(rowvalue) {
      this.updataDialogVisible = true
      this.formvalue = rowvalue
    },
    // 发起修改请求
    async updataUser() {
      await this.$http.put('story', {
        s_id: this.formvalue.s_id,
        s_pid: this.formvalue.s_pid,
        s_name: this.formvalue.s_name,
        s_time: this.formvalue.s_time,
        s_type: this.formvalue.s_type,
        s_about: this.formvalue.s_about
      })
      this.getUserlist()
      this.updataDialogVisible = false
    },
    // 展示删除对话框
    showDeleteDialog(rowvalue) {
      this.deleteDialogVisible = true
      console.log(rowvalue)
      this.formvalue = rowvalue
    },
    // 发起删除请求
    async dleteUser() {
      await this.$http.delete('story?s_id=' + this.formvalue.s_id)
      this.getUserlist()
      this.deleteDialogVisible = false
    }
  }
}
